package com.crazy.crypto.digest;

import java.security.MessageDigest;
import org.apache.commons.codec.digest.DigestUtils;
import static com.crazy.crypto.common.CommonUtil.bytesToHex;

public class MD5Util {

	public static String md5(String src) {
		return DigestUtils.md5Hex(src).toUpperCase();
	}
	
	public static String md5b(String src) throws Exception {
		MessageDigest md = MessageDigest.getInstance("MD5");
	    md.update(src.getBytes("UTF-8"));
	    byte[] digest = md.digest();
	    return bytesToHex(digest).toUpperCase();
	}

	public static void main(String[] args) throws Exception {
		String src = "hello world";
		System.out.println(MD5Util.md5(src));
		System.out.println(MD5Util.md5b(src));
	}
}
